package com.lizhongbao.cloud.feign.web;

import com.alibaba.fastjson.JSONObject;
import com.lizhongbao.cloud.biz.client.BizClient;
import com.lizhongbao.cloud.biz.domain.dto.TestDto;
import com.lizhongbao.cloud.biz.domain.dto.TestQueryDto;
import com.lizhongbao.cloud.biz.domain.eo.Test;
import com.lizhongbao.cloud.feign.client.BizClientRefactor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 测试 Service
 *
 * @Author lizhongbao
 * @Date 2019/12/24 11:16
 **/
@RestController
@RequestMapping("/controller/v1/biz")
public class BizController {

    private static Logger logger = LoggerFactory.getLogger(BizController.class);

    @Autowired
    private BizClient bizClient;

    @Autowired
    private BizClientRefactor bizClientRefactor;

    @RequestMapping(value = "", method = RequestMethod.GET)
    public JSONObject page(TestQueryDto dto,
                    @RequestParam(name = "page", required = false, defaultValue = "1") Long page,
                    @RequestParam(name = "size", required = false, defaultValue = "10") Long size) {
        return bizClient.page(dto, page, size);
    }

    @RequestMapping(value = "/refactor", method = RequestMethod.GET)
    public JSONObject pageRefactor(TestQueryDto dto,
                    @RequestParam(name = "page", required = false, defaultValue = "1") Long page,
                    @RequestParam(name = "size", required = false, defaultValue = "10") Long size) {
        return bizClientRefactor.page(dto, page, size);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public JSONObject list(TestQueryDto dto) {
        return bizClient.list(dto);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Test detail(@PathVariable Long id) {
        return bizClient.detail(id);
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    public Boolean create(@RequestBody @Valid TestDto dto) {
        return bizClient.create(dto);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public Boolean update(@PathVariable Long id, @RequestBody @Valid TestDto dto) {
        return bizClient.update(id, dto);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Boolean delete(@PathVariable Long id) {
        return bizClient.delete(id);
    }

    @RequestMapping(value = "", method = RequestMethod.DELETE)
    public Boolean delete(@RequestParam("id") Long[] ids) {
        return bizClient.delete(ids);
    }

}
